#ifndef JX_UART_SEND_H_
#define JX_UART_SEND_H_

#ifdef __cplusplus
extern "C" {
#endif

// 串口发送消息最大长度
#define UART_SEND_MAX      32
#define UART_MSG_HEAD_LEN_UART0_RX  2
#define UART_MSG_FOOT_LEN_UART0_RX  2

// 串口发送消息号
#define U_MSG_T16      16
#define U_MSG_T17      17
#define U_MSG_T18      18
#define U_MSG_T19      19
#define U_MSG_T20      20
#define U_MSG_T21      21
#define U_MSG_T22      22
#define U_MSG_T23      23
#define U_MSG_T24      24
#define U_MSG_T25      25
#define U_MSG_T26      26
#define U_MSG_T27      27
#define U_MSG_Q1      88
#define U_MSG_Q2      44
#define U_MSG_Q3      55
#define U_MSG_Q4      66
#define U_MSG_T10      10
#define U_MSG_T11      11
#define U_MSG_T12      12
#define U_MSG_T13      13
#define U_MSG_T14      14
#define U_MSG_T15      15
#define U_MSG_T28      28
#define U_MSG_T29      29
#define U_MSG_T30      30
#define U_MSG_T31      31
#define U_MSG_T32      32
#define U_MSG_Q0      77
#define U_MSG_T33      33
#define U_MSG_T34      34
#define U_MSG_T35      35
#define U_MSG_TT      99

// 串口消息参数类型
typedef union {
  double d_double;
  int d_int;
  unsigned char d_ucs[8];
  char d_char;
  unsigned char d_uchar;
  unsigned long d_long;
  short d_short;
  float d_float;
}uart_param_t;

// 十六位整数转32位整数
void _int16_to_int32(uart_param_t* param) {
  if (sizeof(int) >= 4)
    return;
  unsigned long value = param->d_long;
  unsigned long sign = (value >> 15) & 1;
  unsigned long v = value;
  if (sign)
    v = 0xFFFF0000 | value;
  uart_param_t p;
  p.d_long = v;
  param->d_ucs[0] = p.d_ucs[0];
  param->d_ucs[1] = p.d_ucs[1];
  param->d_ucs[2] = p.d_ucs[2];
  param->d_ucs[3] = p.d_ucs[3];
}

// 浮点数转双精度 
void _float_to_double(uart_param_t* param) {
  if (sizeof(int) >= 4)
    return;
  unsigned long value = param->d_long;
  unsigned long sign = value >> 31;
  unsigned long M = value & 0x007FFFFF;
  unsigned long e =  ((value >> 23 ) & 0xFF) - 127 + 1023;
  uart_param_t p0, p1;  
  p1.d_long = ((sign & 1) << 31) | ((e & 0x7FF) << 20) | (M >> 3);
  p0.d_long = (M & 0x7) << 29;
  param->d_ucs[0] = p0.d_ucs[0];
  param->d_ucs[1] = p0.d_ucs[1];
  param->d_ucs[2] = p0.d_ucs[2];
  param->d_ucs[3] = p0.d_ucs[3];
  param->d_ucs[4] = p1.d_ucs[0];
  param->d_ucs[5] = p1.d_ucs[1];
  param->d_ucs[6] = p1.d_ucs[2];
  param->d_ucs[7] = p1.d_ucs[3];
}

// action: T16
void _uart_T16(char temp);

// action: T17
void _uart_T17(char temp);

// action: T18
void _uart_T18(char temp);

// action: T19
void _uart_T19(char temp);

// action: T20
void _uart_T20(char temp);

// action: T21
void _uart_T21(char temp);

// action: T22
void _uart_T22(char temp);

// action: T23
void _uart_T23(char temp);

// action: T24
void _uart_T24(char temp);

// action: T25
void _uart_T25(char temp);

// action: T26
void _uart_T26(char temp);

// action: T27
void _uart_T27(char temp);

// action: Q1
void _uart_Q1(char tq);

// action: Q2
void _uart_Q2(char tq);

// action: Q3
void _uart_Q3(char tq);

// action: Q4
void _uart_Q4(char tq);

// action: T10
void _uart_T10(char temp);

// action: T11
void _uart_T11(char temp);

// action: T12
void _uart_T12(char temp);

// action: T13
void _uart_T13(char temp);

// action: T14
void _uart_T14(char temp);

// action: T15
void _uart_T15(char temp);

// action: T28
void _uart_T28(char temp);

// action: T29
void _uart_T29(char temp);

// action: T30
void _uart_T30(char temp);

// action: T31
void _uart_T31(char temp);

// action: T32
void _uart_T32(char temp);

// action: Q0
void _uart_Q0(char tq);

// action: T33
void _uart_T33(char temp);

// action: T34
void _uart_T34(char temp);

// action: T35
void _uart_T35(char temp);

// action: TT
void _uart_TT(char temp);

#ifdef __cplusplus
}
#endif

#endif /*JX_UART_SEND_H_*/

